﻿using FolderTag.DB.Dbo;
using FolderTag.Model;
using System.Collections.Generic;
using System.Linq;

namespace FolderTag.DB
{
    /// <summary>
    /// 目录PathDb类
    /// </summary>
    public static class FolderPathDb
    {
        /// <summary>
        /// 添加Tag
        /// </summary>
        /// <param name="tagName"></param>
        public static bool Add(PathItem pathItem)
        {
            return DBHelper.SQL_R.Insert(FolderPathDbo.CreateNew(pathItem), false) > 0;
        }

        /// <summary>
        /// 更新Tag
        /// </summary>
        /// <param name="tagItem"></param>
        /// <returns></returns>

        public static bool Update(PathItem pathItem)
        {
            return DBHelper.SQL_R.Update(FolderPathDbo.Create(pathItem)) > 0;
        }
        /// <summary>
        /// 是否存在
        /// </summary>
        /// <param name="tagItem"></param>
        /// <returns></returns>

        public static bool Exists(int id)
        {
            return DBHelper.SQL_R.Count<FolderPathDbo>(x => x.Id == id) > 0;
        }

        public static void Delete(int id)
        {
            DBHelper.SQL_R.Delete<FolderPathDbo>(id);
        }


        /// <summary>
        /// 查询列表
        /// </summary>
        /// <returns></returns>
        public static List<PathItem> QueryList(string parentPath)
        {
            return DBHelper.SQL_R.FindList<FolderPathDbo>(x => x.ParentPath.Equals(parentPath))
                                 .Select(x => new PathItem(x))
                                 .Where(x => x.Type != EPathType.None)
                                 .ToList();
        }
    }
}
